<?php /* SVN: $Id: admin_index.ctp 2883 2010-08-27 12:29:31Z sakthivel_135at10 $ */ ?>
<div class="users index js-response js-responses js-moreaction-responses">
   <div class="js-search-responses">
		<ul class="filter-list-block clearfix ">
     		<li <?php if (!empty($this->request->params['named']['filter_id']) && $this->request->params['named']['filter_id'] == ConstMoreAction::Active) { echo 'class="active"';} ?>><span class="green-block" title="<?php echo __l('Active Users'); ?>"><?php echo $this->Html->link($this->Html->cInt($approved,false).'<span>' .__l('Active Users'). '</span>', array('controller'=>'users','action'=>'index','filter_id' => ConstMoreAction::Active), array('escape' => false));?></span> </li>
     		<li <?php if (!empty($this->request->params['named']['filter_id']) && $this->request->params['named']['filter_id'] == ConstMoreAction::Inactive) { echo 'class="active"';} ?>><span class="red-block" title="<?php echo __l('Inactive Users'); ?>"><?php echo $this->Html->link($this->Html->cInt($pending,false).'<span>' .__l('Inactive Users'). '</span>', array('controller'=>'users','action'=>'index','filter_id' => ConstMoreAction::Inactive), array('escape' => false));?></span> </li>
     		<li <?php if (!empty($this->request->params['named']['filter_id']) && $this->request->params['named']['filter_id'] == ConstMoreAction::Site) { echo 'class="active"';} ?>><span class="brown-block" title="<?php echo __l('Site Users'); ?>"><?php echo $this->Html->link($this->Html->cInt($site_users,false).'<span>' .__l('Site Users'). '</span>', array('controller'=>'users','action'=>'index','filter_id' => ConstMoreAction::Site), array('escape' => false));?></span> </li>
			<li <?php if (!empty($this->request->params['named']['filter_id']) && $this->request->params['named']['filter_id'] == ConstMoreAction::OpenID) { echo 'class="active"';} ?>><span class="grey-block" title="<?php echo __l('OpenID Users'); ?>"><?php echo $this->Html->link($this->Html->cInt($openid,false).'<span>' .__l('OpenID Users'). '</span>', array('controller'=>'users','action'=>'index','filter_id' => ConstMoreAction::OpenID), array('escape' => false));?></span> </li>
     		<li <?php if (!empty($this->request->params['named']['filter_id']) && $this->request->params['named']['filter_id'] == ConstMoreAction::Facebook) { echo 'class="active"';} ?>><span class="blue-block" title="<?php echo __l('Facebook Users'); ?>"><?php echo $this->Html->link($this->Html->cInt($facebook,false).'<span>' .__l('Facebook Users'). '</span>', array('controller'=>'users','action'=>'index','filter_id' => ConstMoreAction::Facebook), array('escape' => false));?></span> </li>
     		<li <?php if (!empty($this->request->params['named']['filter_id']) && $this->request->params['named']['filter_id'] == ConstMoreAction::Twitter) { echo 'class="active"';} ?>><span class="lightblue-block" title="<?php echo __l('Twitter Users'); ?>"><?php echo $this->Html->link($this->Html->cInt($twitter,false).'<span>' .__l('Twitter Users'). '</span>', array('controller'=>'users','action'=>'index','filter_id' => ConstMoreAction::Twitter), array('escape' => false));?></span> </li>
     		<li <?php if (!empty($this->request->params['named']['filter_id']) && $this->request->params['named']['filter_id'] == ConstMoreAction::Gmail) { echo 'class="active"';} ?>><span class="gmail-block" title="<?php echo __l('Gmail Users'); ?>"><?php echo $this->Html->link($this->Html->cInt($gmail,false).'<span>' .__l('Gmail Users'). '</span>', array('controller'=>'users','action'=>'index','filter_id' => ConstMoreAction::Gmail), array('escape' => false));?></span> </li>
     		<li <?php if (!empty($this->request->params['named']['filter_id']) && $this->request->params['named']['filter_id'] == ConstMoreAction::Yahoo) { echo 'class="active"';} ?>><span class="yahoo-block" title="<?php echo __l('Yahoo Users'); ?>"><?php echo $this->Html->link($this->Html->cInt($yahoo,false).'<span>' .__l('Yahoo Users'). '</span>', array('controller'=>'users','action'=>'index','filter_id' => ConstMoreAction::Yahoo), array('escape' => false));?></span> </li>
     		<li <?php if (!empty($this->request->params['named']['filter_id']) && $this->request->params['named']['filter_id'] == ConstMoreAction::AffiliateUser) { echo 'class="active"';} ?>><span class="purple-block" title="<?php echo __l('Affiliate Users'); ?>"><?php echo $this->Html->link($this->Html->cInt($affiliate_user_count,false).'<span>' .__l('Affiliate Users'). '</span>', array('controller'=>'users','action'=>'index','filter_id' => ConstMoreAction::AffiliateUser), array('escape' => false));?></span> </li>
    		<li <?php if (empty($this->request->params['named']['filter_id']) && (!empty($this->request->params['named']['main_filter_id']) and $this->request->params['named']['main_filter_id'] == ConstUserTypes::Admin)) { echo 'class="active"';} ?>><span class="meroon-block" title="<?php echo __l('Admin Users'); ?>"><?php echo $this->Html->link($this->Html->cInt($admin_count,false).'<span>' .__l('Admin Users'). '</span>', array('controller'=>'users','action'=>'index','main_filter_id' => ConstUserTypes::Admin), array('escape' => false));?></span> </li>
     		<li <?php if (empty($this->request->params['named']['filter_id']) and empty($this->request->params['named']['main_filter_id'])) { echo 'class="active"';} ?>><span class="import-block" title="<?php echo __l('Total Users'); ?>"><?php echo $this->Html->link($this->Html->cInt($pending + $approved,false).'<span>' .__l('Total Users'). '</span>', array('controller'=>'users','action'=>'index'), array('escape' => false));?></span> </li>
	  </ul>
<div class="page-count-block clearfix">
	    <div class="grid_left">
	      <?php echo $this->element('paging_counter'); ?>
		</div>
		<div class="grid_left">
            <?php echo $this->Form->create('User', array('type' => 'get', 'class' => 'normal search-form clearfix ', 'action'=>'index')); ?>
            <?php echo $this->Form->input('q', array('label' => __l('Keyword'))); ?>
     		<?php echo $this->Form->submit(__l('Search'));?>
          	<?php echo $this->Form->end(); ?>
		</div>
        <div class="add-block grid_right">
        	 <?php echo $this->Html->link(__l('Add'),array('controller' => 'users', 'action'=>'add'),array('class' => 'add', 'title' => __l('Add New User')));?>
        	 <?php
            	echo $this->Html->link(__l('CSV'), array_merge(array('controller' => 'users', 'action' => 'index', 'ext' => 'csv', 'admin' => true), $this->request->params['named']), array('title' => __l('CSV'), 'class' => 'export'));
           ?>
        </div>
  </div>

<?php echo $this->Form->create('User' , array('class' => 'normal ','action' => 'update')); ?>
<?php echo $this->Form->input('r', array('type' => 'hidden', 'value' => $this->request->url)); ?>
<table class="list">
    <tr>
      <th rowspan="2" class="select"><?php echo __l('Select'); ?></th>
      <th rowspan="2"><?php echo __l('Actions'); ?></th>
      <th rowspan="2"><div class="js-pagination"><?php echo $this->Paginator->sort(__l('user'), 'User.username'); ?></div></th>
      <th rowspan="2"><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Projects'), 'project_count'); ?></div></th>
      <th rowspan="2"><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Project funds'), 'project_fund_count'); ?></div></th>
      <th rowspan="2"><div class="js-pagination"><?php echo __l('Signup fee ($)'); ?></div></th>
	  <?php if(!empty($is_wallet_enabled)) :?>
	  <th rowspan="2"><div class="js-pagination"><?php echo __l('Available balance ($)'); ?></div></th>
	  <?php endif; ?>
      <th colspan="3"><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Logins'), 'user_login_count'); ?></div></th>
      <th rowspan="2"><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Registered On'),'created'); ?></div></th>
    </tr>
    <tr>                      
      <th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Count'), 'user_login_count'); ?></div></th>
      <th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Time'), 'last_logged_in_time'); ?></div></th>
      <th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('IP'), 'last_login_ip_id'); ?></div></th>
    </tr>
<?php
if (!empty($users)):
$i = 0;
foreach ($users as $user):
	$class = null;
	if ($i++ % 2 == 0):
		$class = ' class="altrow"';
	endif;
	if($user['User']['is_active']):
		$status_class = 'js-checkbox-active';
		$td_class = 'admin-status-1';
		$class = ' class="active-record"';
	else:
		$status_class = 'js-checkbox-inactive';
		$td_class = 'admin-status-0';
		$class = ' class="inactive-record"';
	endif;
	$email_active_class = ' email-not-comfirmed';
	if($user['User']['is_email_confirmed']):
		$email_active_class = ' email-comfirmed';
	endif;
	if($user['User']['is_active']):
		$status_class = 'js-checkbox-active';
	else:
		$active_class = ' inactive-record';
		$status_class = 'js-checkbox-inactive';
	endif;
	$online_class = 'offline';
	if (!empty($user['CkSession']['user_id'])) {
		$online_class = 'online';
	}	
?>
	<tr<?php echo $class;?>>
		<td class="select"><?php echo $this->Form->input('User.'.$user['User']['id'].'.id', array('type' => 'checkbox', 'id' => "admin_checkbox_".$user['User']['id'], 'label' => false, 'class' => $status_class.' js-checkbox-list')); ?></td>

        <td class="actions dl">
            <div class="action-block">
                <span class="action-information-block">
                    <span class="action-left-block">&nbsp;&nbsp;</span>
                        <span class="action-center-block">
                            <span class="action-info">
                                <?php echo __l('Action');?>
                             </span>
                        </span>
                    </span>
                    <div class="action-inner-block">
                    <div class="action-inner-left-block">
                        <ul class="action-link clearfix">
			<?php if (Configure::read('user.is_email_verification_for_register') and !$user['User']['is_email_confirmed']):
						echo $this->Html->link(__l('Resend Activation'), array('controller' => 'users', 'action'=>'resend_activation', $user['User']['id'], 'admin' => false),array('class' => 'resend', 'title' => __l('Resend Activation')));
				  endif;
			?>
			<li><?php echo $this->Html->link(__l('Edit'), array('controller' => 'user_profiles', 'action'=>'edit', $user['User']['id']), array('class' => 'edit js-edit', 'title' => __l('Edit')));?></li>
            <?php if($user['User']['user_type_id'] != ConstUserTypes::Admin){ ?>
                <li><?php echo $this->Html->link(__l('Delete'), array('action'=>'delete', $user['User']['id']), array('class' => 'delete js-delete', 'title' => __l('Delete')));?></li>
            <?php } ?>
       <?php if(!($user['User']['is_openid_register']) && !($user['User']['is_yahoo_register']) && !($user['User']['is_gmail_register'])&& !($user['User']['fb_user_id'])&& !($user['User']['twitter_user_id']) ):?>
            <li><?php echo $this->Html->link(__l('Change password'), array('controller' => 'users', 'action'=>'admin_change_password', $user['User']['id']), array('class' => 'change-password', 'title' => __l('Change password')));?></li>
			<?php endif ?>
			<?php if(!empty($user['UserProfile']['paypal_account']) && ($user['User']['user_type_id'] != ConstUserTypes::Admin)): ?>

			<?php endif; ?>
            </ul>        
    					</div>
    					<div class="action-bottom-block"></div>
    				  </div>
              </div>
        </td>
		<?php
			$reg_type_class='';
			$title = '';
			if(!empty($user['User']['is_facebook_register'])):
				$reg_type_class='facebook';
				$title = 'Facebook';
			elseif(!empty($user['User']['is_twitter_register'])):
				$reg_type_class='twitter';
				$title = 'Twitter';				
			 elseif(!empty($user['User']['is_gmail_register'])):
				$reg_type_class='open-id-gmail-thumb';
				$title = 'Gmail';								
			elseif(!empty($user['User']['is_yahoo_register'])):
				$reg_type_class='open-id-yahoo-thumb';
				$title = 'Yahoo';								
			elseif(!empty($user['User']['is_openid_register'])):
				$reg_type_class='open-id-thumb';
				$title = 'OpenID';								
			 endif;
		?>
		<td class=" users-actions dl">
                                <div class="clearfix user-info-block">
                        <p class="user-img-left grid_left">
                        	<?php
						echo $this->Html->getUserAvatar($user['User']['id'], 'micro_thumb');
						?>
                            <?php
 echo $this->Html->link($this->Html->cText($user['User']['username']), array('controller'=> 'users', 'action' => 'view', $user['User']['username'], 'admin' => false), array('escape' => false,'title'=>$this->Html->cText($user['User']['username'],false)));								
                            ?>
                            </p>
                              <p class="user-img-right grid_right">
                      
                        <?php if($user['User']['is_affiliate_user']):?>
								<span class="affiliate round-3"> <?php echo __l('Affiliate'); ?> </span>
						<?php endif; ?>
						  <?php if($user['User']['user_type_id'] == ConstUserTypes::Admin):?>
								<span class="admin"> <?php echo __l('Admin'); ?> </span>
						<?php endif; ?>
						</p>
                        </div>
                        <div class="clearfix user-status-block user-info-block">
                        <?php 					
							if(!empty($user['UserProfile']['Country'])):
								?>
                                <span class="flags flag-<?php echo strtolower($user['UserProfile']['Country']['iso2']); ?>" title ="<?php echo $user['UserProfile']['Country']['name']; ?>">
									<?php echo $user['UserProfile']['Country']['name']; ?>
								</span>
                                <?php
	                        endif; 
						?>    
			          <?php if ($reg_type_class) { ?>
			          	<span class ="<?php echo $reg_type_class; ?>" title="<?php echo $title; ?>">&nbsp;</span>
			          	<?php } ?>
                        <?php if(!empty($user['User']['email'])):?>
								<span class="email <?php echo $email_active_class; ?>" title="<?php echo $user['User']['email']; ?>">
								<?php 
								if(strlen($user['User']['email'])>20) :
									echo '..' . substr($user['User']['email'], strlen($user['User']['email'])-15, strlen($user['User']['email'])); 
								else:
									echo $user['User']['email']; 
								endif; 
								?> 
                                </span>
						<?php endif; ?>
		                       
						</div>
        </td>
    <td><?php echo $this->Html->link($this->Html->cInt($user['User']['project_count']), array('controller' => 'projects', 'action' => 'index', 'user_id' => $user['User']['id']), array('escape' => false));?></td>

        <td><?php echo $this->Html->link($this->Html->cInt($user['User']['project_fund_count']), array('controller' => 'project_funds', 'action' => 'index', 'user_id' => $user['User']['id']), array('escape' => false));?></td>
        <td class="site-amount"><?php if(isset($user['Transaction']['0']['amount'])) { echo $this->Html->cInt($user['Transaction']['0']['amount']); } else { echo '-';}?></td>
		<?php if(!empty($is_wallet_enabled)) :?>
		<td class="commission-amount"><?php if(isset($user['User']['available_wallet_amount'])) { echo $this->Html->cInt($user['User']['available_wallet_amount']); } else { echo '-';}?></td>
        <?php endif; ?>
        <td><?php echo $this->Html->link($this->Html->cInt($user['User']['user_login_count']), array('controller' => 'user_logins', 'action' => 'index', 'user_id' => $user['User']['id']), array('escape' => false));?></td>
        <td>
		<?php if($user['User']['last_logged_in_time'] == '0000-00-00 00:00:00' || empty($user['User']['last_logged_in_time'])){
            echo '-';
        }else{
            echo $this->Html->cDateTimeHighlight($user['User']['last_logged_in_time']);
        }?>
        </td>
        <td class="ip-block">
                        <?php if(!empty($user['LastLoginIp']['ip'])): ?>							  
                            <?php echo  $this->Html->link($user['LastLoginIp']['ip'], array('controller' => 'users', 'action' => 'whois', $user['LastLoginIp']['ip'], 'admin' => false), array('target' => '_blank', 'title' => 'whois '.$this->Html->cText($user['LastLoginIp']['host'],false), 'escape' => false)); ?> 
							<p>
							<?php 					
                            if(!empty($user['LastLoginIp']['Country'])):
                                ?>
                                <span class="flags flag-<?php echo strtolower($user['LastLoginIp']['Country']['iso2']); ?>" title ="<?php echo $user['LastLoginIp']['Country']['name']; ?>">
									<?php echo $user['LastLoginIp']['Country']['name']; ?>
								</span>
                                <?php
                            endif; 
							 if(!empty($user['LastLoginIp']['City'])):
                            ?>             
                            <span> 	<?php echo $user['LastLoginIp']['City']['name']; ?>    </span>
                            <?php endif; ?>
                            </p>
                        <?php else: ?>
							<?php echo __l('N/A'); ?>
						<?php endif; ?>            
        </td>

		

		<td><?php echo $this->Html->cDateTimeHighlight($user['User']['created']);?></td>
	</tr>
<?php
    endforeach;
else:
?>
	<tr>
		<td colspan="14" class="notice"><?php echo __l('No users available');?></td>
	</tr>
<?php
endif;
?>
</table>

<?php
if (!empty($users)):
?>
<div class="clearfix">
	<div class="admin-select-block grid_left">
		<?php echo __l('Select:'); ?>
		<?php echo $this->Html->link(__l('All'), '#', array('class' => 'js-admin-select-all', 'title' => __l('All'))); ?>
		<?php echo $this->Html->link(__l('None'), '#', array('class' => 'js-admin-select-none', 'title' => __l('None'))); ?>
		<?php echo $this->Html->link(__l('Inactive'), '#', array('class' => 'js-admin-select-pending', 'title' => __l('Inactive'))); ?>
		<?php echo $this->Html->link(__l('Active'), '#', array('class' => 'js-admin-select-approved', 'title' => __l('Active'))); ?>
	</div>
	<div class="admin-checkbox-button grid_4 grid_left"><?php echo $this->Form->input('more_action_id', array('class' => 'js-admin-index-autosubmit', 'label' => false, 'empty' => __l('-- More actions --'))); ?></div>
  	<div class="js-pagination grid_right">
        <?php echo $this->element('paging_links'); ?>
    </div>
      </div>
    <div class="hide">
	    <?php echo $this->Form->submit('Submit'); ?>
    </div>
<?php
endif;
echo $this->Form->end();
?>
   </div>
</div>